//
//  LRJ_FontStandard.c
//  LRJAansyDraw
//
//  Created by imac_LRJ on 2022/6/9.
//

#include "LRJ_FontStandard.h"

const LRJ_FontStandard LRJ_FontMetricsZero = {0, 0, 0};
const LRJ_FontStandard LRJ_FontMetricsNull = {NSNotFound, NSNotFound, NSNotFound};

static LRJ_FontStandard WMGCachedFontMetrics[13];

LRJ_FontStandard WMGFontDefaultMetrics(NSInteger pointSize)
{
    if (pointSize < 8 || pointSize > 20)
    {
        UIFont *font = [UIFont systemFontOfSize:pointSize];
        return LRJ_FontStandardMakeFromUIFont(font);
    }
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        @autoreleasepool {
            for (NSInteger i = 0; i < 13; i++) {
                NSUInteger pointSize = i + 8;
                UIFont * font = [UIFont systemFontOfSize:pointSize];
                WMGCachedFontMetrics[i] = LRJ_FontStandardMakeFromUIFont(font);
            }
        }
    });
    
    return WMGCachedFontMetrics[pointSize - 8];
}

